
(function () { 
	Codestrong.ui.CreateLectureMain = function () {

//var LectureMain = function() {
	var aps='';
	
	if(Ti.Platform.osname== 'android') {
  		 Titanium.include('../globals.js');
  		
  		 aps='../';
    }
    else {
   		 Titanium.include('globals.js');
   	
    }
    /////////////////////EVENT//////////
	var data = []; 
	var response;
    ////////////////////////////////////FUNTION///////////////////////
    ////////////////////////////////////////////////////////////
        
    var win = Titanium.UI.createWindow({
            id: 'lectureWindow',
            title: 'BÀI GIẢNG',
            backgroundColor: '#FFF',
            barColor: '#414444',
            fullscreen: false
           
        });
       
    var egc = new globals.EventGarbageCollection(win);
	
	
	egc.addEventListener('LectureMain:CreateLectureBySubject', function(data) {
		//	alert(data.dataLecture)
		Codestrong.navGroup.open(Codestrong.ui.CreateLectureBySubject({
    	    IDMon:data.IDMon,
    	    TenMonHoc:data.TenMonHoc,
    	    data:data
		}), 
		{
		    animated: true,
		    navBarHidden:true
		});				
    })
    
    egc.addEventListener('LectureMain:CreateLectureCategory', function() {
	
		Codestrong.navGroup.open(Codestrong.ui.CreateLectureCategory({
		}), 
		{
		    animated: true,
		    navBarHidden:true
		});				
    })
   egc.addEventListener('LectureMain:CreateSearchLecture', function() {
	
		Codestrong.navGroup.open(Codestrong.ui.CreateSearchLecture({
		}), 
		{
		    animated: true,
		    navBarHidden:true
		});				
    })
    
    
    egc.addEventListener('back_LectureMain', function () {
    	Codestrong.navGroup.close(win, {
                        animated: true
        });
    	
	});
	////////////main_header///////////////////////////
	 var databutton_right=[
    	{Id:1,Image:aps+'images/list_bullets.png',Image_:aps+'images/list_bullets_.png',tag:'Category'},
	    {Id:2,Image:aps+'images/account.png',Image_:aps+'images/account_.png',tag:'Login'},
	    {Id:3,Image:aps+'images/search.png',Image_:aps+'images/search_.png',tag:'Search'},
	    
	]
	
	
	var main_header=require('controls/main_header').main_header({
	 		backgroundImage: aps+'images/panel3.png',
	 		headertext:'Thầy trò Mobile: Bài Giảng',
		    left: 0,
		    top: 0,
		    height:65,
		    width: '100%',//Titanium.Platform.displayCaps.platformWidth,
		    touchEnabled: true		,
		    databutton_right:databutton_right,
		 
		    imback:   aps+'images/back.png',
		    imback_:   aps+'images/back_.png',
		  	idWinParent:'LectureMain',
		    
    })

	win.add(main_header);
  
        
        
	
	///////////////////////////////////////////////////////////
	ScrollViewMain = Ti.UI.createScrollView({
		top:main_header.height
	});
	
	
	
	////////////main_imagetop///////////////////////////
	
	var spaceimage=1,sizeimage=200
	
 	var scrollViewImage = Titanium.UI.createScrollView({
			contentWidth:'auto',
			contentHeight:'auto',
			top:0,//main_header.height+main_header.top,
			width:'100%',
			height:200,
			scrollType: 'horizontal',
			
			
			
			
			
	});	
	var mobilier = [];
	mobilier[0] = aps+'images/teacher/slide_11.jpg';
	mobilier[1] = aps+'images/teacher/slide_12.jpg';
	mobilier[2] = aps+'images/teacher/slide_13.jpg';
	mobilier[3] = aps+'images/teacher/slide_14.jpg';
	mobilier[4] = aps+'images/teacher/slide_16.jpg';
	mobilier[5] = aps+'images/teacher/slide_19.jpg';
	mobilier[6] = aps+'images/teacher/slide_23.jpg';
	
	
	for(var i = 0; i < mobilier.length; i++) {
		
			var image=require('controls/main_imagetop').main_imagetop({
			        top:0,
			        left:i*(sizeimage+spaceimage),
			        height:200,
			        width:200,
			        backgroundColor:'transparent',
			        image:mobilier[i],
			        info:'Thông tin mẩu '+i
			 })
			scrollViewImage.add(image)
	}
	
	ScrollViewMain.add(scrollViewImage)
	
	
	
	
	
	
	/////////////////////////////////////////////////////////////
	
	var db = require('db');
	var Items_Lop = db.getLop();
	var heighttable=113//130
	//var data = [{title:'CPF Cloud Login', hasChild:true, url:'tmlogin.html'}];  


	var topview=scrollViewImage.top+scrollViewImage.height;
	
	for (var i = 0; i < Items_Lop.length; i++) {
		 var datablock = [];
		 var dataimage = [];
		 var dataMonHoc = [];
		 var dataID = [];
		 var IdLop= Items_Lop[i].Id;
		 var TenLop= Items_Lop[i].Name;
		 var Items_MonHoc = db.getMonHoc(IdLop);

		 for (var j = 0; j < Items_MonHoc.length; j++) {
		 	datablock[j] = Items_MonHoc[j].Name;
		 	dataimage[j] = aps+'images/'+Items_MonHoc[j].Images;
		 	dataID[j] = Items_MonHoc[j].Id;
		 	dataMonHoc[j] = Items_MonHoc[j];
		 }
		
		 
		var height_tableblock=Math.round((datablock.length/2))*heighttable
	
		var main_blocksubject=require('controls/main_blocksubject').main_blocksubject({
		  			 heightview:45,
					 widthview:'100%',//Globals.platformWidth,
					 leftview:0,
		  			 topview:topview,
		  			 infolabel:TenLop,
		  			 width_viewheader:'100%',//Globals.platformWidth,
		  			 height_viewheader:45,
		  			 backgroundImage_viewheader:aps+'images/panel.png',
		  			 datablock:datablock,
		  			 dataimage:dataimage,
		  			 dataID:dataID,
		  			 dataMonHoc:dataMonHoc,
		  			 height_tableblock:height_tableblock,
		  			 height_table:heighttable,
		  			 backgroundImageTable:aps+'images/bgTable.png',
		  			// backgroundImageSection:aps+'images/bgTable.png',
		  			 backgroundColorSection:'#2981a3'
		  			 //urljson:Globals.serviceurl_GetListLectureTopNew,
			    })
	
		ScrollViewMain.add(main_blocksubject);
		topview=topview+main_blocksubject.height
	
	}
	
	
	
	win.add(ScrollViewMain);
	
	win.addEventListener('open', function(e)
	{
		/*
	    var top = 0, h = 200, numOfView = mobilier.length;
		var j = 1;
		var interval = setInterval(function() {
		    if ( j == numOfView) {
		        j = 1;
		        scrollViewImage.scrollTo(0, 0);
		        //clearInterval(interval);
		    } else {
		        scrollViewImage.scrollTo(h * j,0);
		        j++;
		    }
		}, 3000);
		*/
	});
	




 return win;
       
    };
})();